package youcaihuaoa.weetop.com

import android.app.Activity
import android.bluetooth.le.ScanSettings
import android.content.Context
import android.os.Bundle
import cn.bingoogolapple.swipebacklayout.BGASwipeBackHelper
import cn.jpush.android.api.JPushInterface
import cn.wandersnail.ble.EasyBLE
import cn.wandersnail.ble.ScanConfiguration
import cn.wandersnail.ble.ScannerType
import cn.wandersnail.commons.poster.ThreadMode
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.LogUtils
import com.robot.base.configs.AppConstants
import com.robot.base.configs.PrefsManager
import com.robot.base.util.AppUtils
import com.robot.base.util.DensityAdaptationUtils
import com.robot.base.util.ToastUtils
import com.robot.base.util.debounce.AntiShake
import com.scwang.smartrefresh.header.MaterialHeader
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
import com.tencent.tauth.Tencent
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig
import me.goldze.mvvmhabit.base.BaseApplication
import me.goldze.mvvmhabit.crash.CaocConfig
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.Utils
import io.rong.imkit.IMCenter

import io.rong.imlib.model.InitOption




class GlApp : BaseApplication() {

    companion object {
        private var context: GlApp? = null
        private const val UM_KEY = "586c904907fe656adc00197a"
        const val WX_KEY = "wx3ba86c39e9dd9309"

        // APP_ID 替换为你的应用从官方网站申请到的合法appID
        const val APP_ID = "wxdee98193ad267356"
        var mApp: GlApp? = null
        var mAntiShake: AntiShake? = null
        var checkProtocol = false
        var phoneCount = 0
        var isCheck = false

        fun getInstance(): GlApp {
            return mApp!!
        }

        @JvmStatic
        fun getContext(): Context? {
            return context
        }

        //static 代码段可以防止内存泄露
        init {
            //设置全局的Header构建器
            SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, _ ->
                MaterialHeader(context)
            }
            //设置全局的Footer构建器
            SmartRefreshLayout.setDefaultRefreshFooterCreator { context, _ ->
                ClassicsFooter.REFRESH_FOOTER_FINISH = "加载中..."
                ClassicsFooter.REFRESH_FOOTER_LOADING = "加载中..."
                ClassicsFooter.REFRESH_FOOTER_NOTHING = "已经全部加载完毕"
                ClassicsFooter(context).setDrawableSize(20f)
            }
        }
    }

    override fun onCreate() {
        super.onCreate()
        context = this
        AppUtils.init(this)
        Utils.init(this)
        PrefsManager.load(this)
        ARouter.openDebug()
        ARouter.init(this)
        BGASwipeBackHelper.init(this, null)
//        AlphaManager.getInstance(this).start()
        //是否开启日志打印
        KLog.init(true)
        //配置全局异常崩溃操作
        DensityAdaptationUtils.setDensity(context!!, 375f)
        CaocConfig.Builder.create()
            .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //背景模式,开启沉浸式
            .enabled(true) //是否启动全局异常捕获
            .showErrorDetails(true) //是否显示错误详细信息
            .showRestartButton(true) //是否显示重启按钮
            .trackActivities(true) //是否跟踪Activity
            .minTimeBetweenCrashesMs(2000) //崩溃的间隔时间(毫秒)
            .errorDrawable(R.mipmap.ic_launcher) //错误图标
            //                .restartActivity(LoginActivity.class) //重新启动后的activity
            //.errorActivity(YourCustomErrorActivity.class) //崩溃后的错误activity
            //.eventListener(new YourCustomEventListener()) //崩溃后的错误监听
            .apply()
        initDir()
        val appKey = "sfci50a7sm9ji" // example: bos9p5rlcm2ba

        val initOption = InitOption.Builder().build()
//
        IMCenter.init(this, appKey, initOption)

        ToastUtils.setMsgColor(ColorUtils.getColor(R.color.app_white))
        ToastUtils.setBgColor(ColorUtils.getColor(R.color.app_2E000000))
    }

    private fun initDir() {
        AppConstants.BizKey.DIR_APK = "$filesDir/apk"
    }
}